﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BUS;
using System.Data;
namespace AirPlane.UserConTrol
{
    public partial class WUCTraCuuChuyenBay : System.Web.UI.UserControl
    {
        protected SanBayBUS sb = new SanBayBUS();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                datepickerdepart.Text = DateTime.Now.Date.ToShortDateString();
                datepickergoing.Text = DateTime.Now.Date.AddDays(3).ToShortDateString();
                ddlSanBayDi.DataSource = sb.loadSanBayDi();
                ddlSanBayDi.DataBind();
                ddlSanBayDen.DataSource = sb.loadSanBayDen();
                ddlSanBayDen.DataBind();
                Label1.Text = "";
            }
        }

        protected void btn_go_Click(object sender, EventArgs e)
        {
            string maSanBayDi = ddlSanBayDi.SelectedValue.ToString();
            string maSanBayDen = ddlSanBayDen.SelectedValue.ToString();
            string thoiGianDi = datepickerdepart.Text;
            string thoiGianVe = datepickergoing.Text;
            int type = int.Parse(rdKhuHoi.SelectedValue.ToString());
            ChuyenBayBUS bus = new ChuyenBayBUS();
            DataTable dt = new DataTable();
        
            dt = bus.TimKiemChuyenBay(maSanBayDi, maSanBayDen, thoiGianDi);
           
            if (dt.Rows.Count == 0)
                Label1.Text = "<span id = 'thong-bao-ket-Qua-Tim-Kiem'>Không tìm thấy chuyến bay!</span>";
            else
            Response.Redirect("TimKiemChuyenBay.aspx?maSanBayDi=" + maSanBayDi + "&maSanBayDen=" + maSanBayDen + "&thoiGianDi=" + thoiGianDi + "&thoiGianDen=" + thoiGianVe + "&type=" + type);
        }

        protected void ddlSanBayDi_SelectedIndexChanged(object sender, EventArgs e)
        {
            //ddlSanBayDen.DataSource = "";
            //SanBayBUS bus = new SanBayBUS();
            //ddlSanBayDen.DataSource = bus.layDanhSachSanBay(ddlSanBayDi.SelectedValue.ToString());
            
        }

    }
}